package GUI;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

@SuppressWarnings("serial")
/**
 * Manager's side bar containing all of its commands
 * @author Benny
 *
 */
public class LibraryManagerSideBarGUI extends LibrarianSideBarGUI {

	/**
	 * Create the panel.
	 * @param M Instance of the main Frame of the program
	 */
	public LibraryManagerSideBarGUI(MainFrame M) {
		super(M);
		
		JButton btnReports = new JButton("Reports");
		btnReports.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				for (int i = mf.managerMain.reports.searchTableModel1.getRowCount() - 1; i >= 0; i--){ 
					mf.managerMain.reports.searchTableModel1.removeRow(i);
				 }
				mf.managerMain.reports.setVisible(true);
				mf.managerMain.cardManaging.setVisible(false);
				mf.managerMain.regBorrowGUI.setVisible(false);
				mf.librarianMain.bookReturn.setVisible(false);
				mf.librarianMain.bookBorrow.setVisible(false);
				mf.librarianMain.manualExtend.setVisible(false);
				mf.librarianMain.searchBook.setVisible(false);
				mf.librarianMain.viewUser.setVisible(false);
				mf.librarianMain.registerNewUser.setVisible(false);
				mf.managerMain.activityGUI.setVisible(false);
			}
		});
		btnReports.setBounds(10, 396, 160, 42);
		add(btnReports);
		
		JButton btnCardManaging = new JButton("Card Managing");
		btnCardManaging.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ArrayList<Object> send = new ArrayList<>();
				send.add("3");
				send.add("ShowUserToFreeze");
                 mf.client.accept(send);
                 
                 for(int i=0;i<mf.managerMain.cardManaging.freezeTableModel.getRowCount();i++)
                	 mf.managerMain.cardManaging.freezeTableModel.removeRow(i);
             	
             	for(int i=0;i<mf.managerMain.cardManaging.unfreezeTableModel.getRowCount();i++)
             		mf.managerMain.cardManaging.unfreezeTableModel.removeRow(i);
                 
				mf.managerMain.reports.setVisible(false);
				mf.managerMain.cardManaging.setVisible(true);
				mf.managerMain.activityGUI.setVisible(false);
				mf.managerMain.regBorrowGUI.setVisible(false);
				mf.librarianMain.bookReturn.setVisible(false);
				mf.librarianMain.bookBorrow.setVisible(false);
				mf.librarianMain.manualExtend.setVisible(false);
				mf.librarianMain.searchBook.setVisible(false);
				mf.librarianMain.viewUser.setVisible(false);
				mf.librarianMain.registerNewUser.setVisible(false);
				
			}
		});
		btnCardManaging.setBounds(10, 449, 160, 42);
		add(btnCardManaging);
		
		ImageIcon img = new ImageIcon(getClass().getResource(
                "/util/grad.png"));
		JLabel picLabel = new JLabel(img);
		picLabel.setLocation(0, 0);
		picLabel.setSize(185, 580);
		add(picLabel);

	}
}
